require(['jquery', 'cookie', 'app', 'lay'], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: [],
                that: {

                }
            }
            , created: function () {
                this.seachs();
            }
            , methods: {
                loadPage: function () {
                    var re = playAjax("bsp/45").data;
                    var toolbar = [];
                    if(fspuser["role"]=='1'){
                        toolbar.push({
                            "clas": "layui-btn-warm",
                            "eve": "ADD",
                            "tit": "增加",
                            "fnc": function (data) {
                                window.parent.sp.showTab({id: getCode(2), name: '新增优惠券', url: './vsp/49'})
                            }
                        });
                    }
                    toolbar.push({
                        "clas": "layui-btn-warm",
                        "eve": "SSL",
                        "tit": "赠送优惠券",
                        "fnc": function (data) {
                            if (data.length == 0) {
                                alr("请选中一行！");
                                return false;
                            } else {
                                layer.open({
                                    type: 2
                                    , content: "./51"
                                    , area: ["800px", "400px"]
                                    , btn: ['确定', '取消']
                                    , yes: function (index, layero) {
                                        var body = layer.getChildFrame('body', index);
                                        var w = $(layero).find("iframe")[0].contentWindow;
                                        var jon = w.checkSure();
                                        var re=playAjax("/SaleController/UserSave",{sale:{uuid:data[0].uuid},user:{uuid:jon['uuid']}});
                                        alr(re.msg);
                                        setTimeout(function () {
                                            window.reload();
                                        },500)

                                    }
                                    , btn2: function (index, layero) {
                                        layer.closeAll();
                                    }
                                    , cancel: function () {
                                        layer.closeAll();
                                    }
                                });
                            }
                        }
                    })
                    bspVIEW($(".sa-table"), "SaleController/List", re, this.where, toolbar);
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                referXadmin: function () {
                    window.location.reload();
                },
            }
        });
    })
});
function update(uuid) {
    window.parent.sp.showTab({id: getCode(2), name: '修改优惠券', url: './vsp/49?uuid='+uuid})
}
function deleted(uuid) {
    var re = playAjax("/SaleController/Del",{uuid:uuid});
    alr(re.msg);
    if(re.code==200){
        setTimeout(function () {
            window.reload();
        },500);
    }
}
